<?php
$cs = Yii::app()->clientScript;
$cs->registerScriptFile(Yii::app()->theme->baseUrl.'/scripts/fancybox/jquery.fancybox-1.3.4.pack.js');
$cs->registerCssFile(Yii::app()->theme->baseUrl.'/scripts/fancybox/jquery.fancybox-1.3.4.css');

$this->breadcrumbs=array(
    'Pages'=>array('index'),
    'Compare',
);

$this->menu=array(
);

$script = "
jQuery('.grid-view').delegate('.sync_page', 'click', function(){
    if (confirm('Are you sure you want to sync this page?'))
    {
        jQuery.get(jQuery(this).attr('href'), function(){
            window.location = window.location.href.replace(/\#.*/, '');
        });
    }
    return false;
});

jQuery('.grid-view').delegate('.sync_to_right_pages, .sync_to_left_pages', 'click', function(){
    var side = 'right';
    var index = 1;
    if (jQuery(this).hasClass('sync_to_left_pages'))
    {
        side = 'left';
        index = 2;
    }
    if (confirm('Are you sure you want to copy to '+side+' all pages?'))
    {
        jQuery('.items tr:gt(0)').each(function(){
            var sync_link = jQuery('td:eq('+index+') a.sync_page', this);
            if (sync_link.size())
            {
                jQuery.ajax({
                    async : false,
                    type : 'get',
                    url : sync_link.attr('href')
                });
            }
        });
        window.location = window.location.href.replace(/\#.*/, '');
    }
    return false;
});

if (jQuery('a[title=\"Copy to Left\"]').size())
{
    jQuery('.sync_to_left_pages').show();
}

if (jQuery('a[title=\"Copy to Right\"]').size())
{
    jQuery('.sync_to_right_pages').show();
}
";
$cs->registerScript(__CLASS__.'#SyncPage', $script);

$script = "
jQuery('.grid-view').delegate('.compare-details', 'click', function(){
    jQuery.fancybox({
        'titleShow' : false,
        'type' : 'iframe',
        'href' : jQuery(this).attr('href'),
    });
    return false;
});
";
$cs->registerScript(__CLASS__.'#CompareDetails', $script);
?>

<h2>Compare workflow <?php echo $source->name;?> and <?php echo $target->name;?></h2>
<style type="text/css">
.grid-view ul {padding: 0; display: block; margin: 0;}
.grid-view ul li {list-style: none;}
.grid-view .sort-handle {cursor: move;}
.grid-view table.items {border-bottom: 1px solid #FFFFFF;}
#list-container ul {padding-left: 20px;}
.ordering-updated {background: url(<?php echo Yii::app()->theme->baseUrl;?>/images/notifications.gif) 10px center #EEEEEE no-repeat; padding: 5px 0 5px 30px; margin: 10px 0;}
.placeholder {background: #DBDBDB; border-bottom: 1px solid #FFFFFF;}
.grid-view table.items th, .grid-view table.items td { border: 1px solid white;}
.grid-view table.items th { border-bottom: 1px solid #DDDDDD; }
.grid-view .status-column {width: 38px;}
.sync_to_left_pages,
.sync_to_right_pages {
    display: none;
}
</style>

<div class="grid-view">
    <table class="items">
        <thead>
            <tr>
                <th align="center" width="20"><?php echo CHtml::checkBox('check_all', false, array('class'=>'check-all'));?></th>
                <th align="left">Page</th>
                <th width="200">
                    <?php echo $source->name;?>
                    <?php echo CHtml::link(CHtml::image(Yii::app()->theme->baseUrl.'/images/copy_to_right.png', 'Copy All to Right', array('align'=>'top')), '#', array('title'=>'Copy All to Right', 'class'=>'sync_to_right_pages'));?>
                </th>
                <th width="200">
                    <?php echo CHtml::link(CHtml::image(Yii::app()->theme->baseUrl.'/images/copy_to_left.png', 'Copy all to Left', array('align'=>'top')), '#', array('title'=>'Copy all to Left', 'class'=>'sync_to_left_pages'));?>
                    <?php echo $target->name;?>
                </th>
            </tr>
        </thead>
    </table>
<?php if (count($models)):?>
    <ul id="list-container">
        <?php $this->renderCompareNestedPage(dirname(__FILE__).DIRECTORY_SEPARATOR.'_compare_item.php', $models, $source->id, $target->id);?>
    </ul>
<?php else:?>
    <table class="items">
        <tr class="odd">
            <td colspan="4"><?php echo Yii::t('zii','No results found.');?></td>
        </tr>
    </table>
<?php endif;?>
</div>